<template>
	<view class="tabs">
		<view style="height: 100rpx;background-color: #FFFFFF;" class="page-section-spacing">
			<view class="scroll-view-item_H" v-for="(item,index) in tabList" @tap="changeTab(index)">
				<view class="animate__animated" hover-class="animate__rubberBand"
					:class="index == isActive ? 'active' :''">
					{{item.name}}
				</view>
				<view class="" :class="index == isActive ? 'line' :''"></view>
			</view>
		</view>
		<!-- 待处理 -->
		<view class="page-section-spacing" v-if="this.isActive===0">
			<scroll-view :refresher-triggered=refresherTriggered :refresherThreshold=refresherThreshold
				@refresherrefresh='refresherrefresh()' refresher-background="#FFFFFF" lower-threshold="500" class=""
				scroll-y :style="{height: orderHeight+'px'}">
				<view class="all-box">
					<view class="pannel" v-for="(item,index) in LeaveLog" :key='index' @tap="leaveInfo(item.id)">
						<view class="applyname">
							<view class="">
								申请人：{{item.applyUserName}}
							</view>
							<view class="">
								{{item.createTime}}
							</view>
						</view>
						<view class="">
							<view class="casetype">
								<view class="">
									请假类型：
								</view>
								<view class="">
									{{item.typeName}}
								</view>
					
							</view>
					
						</view>
						<view class="case">
							<view class="">
								请假原因：
							</view>
							<view class="">
								{{item.reason}}
							</view>
					
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- 已通过 -->
		<view class="page-section-spacing" v-if="this.isActive===1">
			<scroll-view :refresher-triggered=refresherTriggered :refresherThreshold=refresherThreshold
				@refresherrefresh='refresherrefresh()' refresher-background="#FFFFFF" lower-threshold="500" class=""
				scroll-y :style="{height: orderHeight+'px'}">
				<view class="all-box" v-for="(item,index) in LeaveLog" :key='index'>
					<view class="pannel1">
						<view class="applyname1">
							<view class="">
								申请人：{{item.applyUserName}}
							</view>
							<view class="">
								{{item.createTime}}
							</view>
						</view>
						<view class="">
							<view class="casetype1">
								<view class="">
									请假类型：
								</view>
								<view class="">
									{{item.typeName}}
								</view>
					
							</view>
					
						</view>
						<view class="case1">
							<view class="">
								请假原因：
							</view>
							<view class="">
								{{item.reason}}
							</view>
					
						</view>
					</view>
				</view>

			</scroll-view>
		</view>
		<!-- 已拒绝 -->
		<view class="page-section-spacing" v-if="this.isActive===2">
			<scroll-view :refresher-triggered=refresherTriggered :refresherThreshold=refresherThreshold
				@refresherrefresh='refresherrefresh()' refresher-background="#FFFFFF" lower-threshold="500" class=""
				scroll-y :style="{height: orderHeight+'px'}">
				<view class="all-box" v-for="(item,index) in LeaveLog" :key='index'>
					<view class="pannel">
						<view class="applyname1">
							<view class="">
								申请人：{{item.applyUserName}}
							</view>
							<view class="">
								{{item.createTime}}
							</view>
						</view>
						<view class="">
							<view class="casetype1">
								<view class="">
									请假类型：
								</view>
								<view class="">
									{{item.typeName}}
								</view>

							</view>

						</view>
						<view class="case1">
							<view class="">
								请假原因：
							</view>
							<view class="">
								{{item.reason}}
							</view>

						</view>
						<view class="line_l">
						</view>
						<view class="case">
							<view class="">
								拒绝原因：
							</view>
							<view class="">
								{{item.replay}}
							</view>

						</view>
					</view>
					</view>
			</scroll-view>
		</view>

	</view>
</template>

<script>
	import uQRCode from '@/js_sdk/Sansnn-uQRCode/uqrcode.js'
	export default {
		data() {
			return {
				orderHeight: 500,
				isActive: 0,
				tabList: [{
						id: "1",
						name: '待处理'
					}, {
						id: "2",
						name: '已通过'
					},
					{
						id: "3",
						name: '已拒绝'
					},
				],
				hasNextPage: true,
				refresherThreshold: 50,
				refresherTriggered: false,
				_refresherTriggered: false,
				pageNum: 1,
				pageSize: 20,
				payState:'',
				LeaveLog:''
			}
		},
		onReady() {
			let that = this;
			uni.getSystemInfo({ //调用uni-app接口获取屏幕高度
				success(res) { //成功回调函数
					that.orderHeight = res.windowHeight - uni.upx2px(100) //windoHeight为窗口高度，主要使用的是这个
				}
			})
		},
		onShow() {
			uni.$on("backdata", res => {
				console.log(res)
			        // 清除监听
					this.changeTab(res)
			        uni.$off('handleFun');
			    })
		},
		onLoad(option) {
			console.log(option.number)
			if(option.number!==undefined){
				this.changeTab(option.number)
			}else{
				this.changeTab(0)
			}
			
		},
		methods: {
			//跳转请假详情页面
			leaveInfo(id){
				console.log(1)
				uni.navigateTo({
					url:'./leaveInfo?id='+id
				})
			},
			refresherrefresh() {
				console.log("自定义下拉刷新被触发");
				let _this = this;
				if (_this._refresherTriggered) {
					return;
				}
				_this._refresherTriggered = true;
				//界面下拉触发，triggered可能不是true，要设为true
				if (!_this.refresherTriggered) {
					_this.refresherTriggered = true;
				}
				// this.getClassOrdersList(_this.payState)
				setTimeout(() => {
					_this.refresherTriggered = false; //触发onRestore，并关闭刷新图标
					_this._refresherTriggered = false;
				}, 1500)

			},
			// 时间转换
			renderTime(date) {
				var dateee = new Date(date).toJSON();
				return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/,
					'')
			},
			//点击事件改变swiper
			changeTab(active) {
				this.isActive = active
				if (active == 0) {
					this.payState = 0
					console.log(this.isActive)
				} else if (active == 1) {
					this.studentlist = ''
					this.payState = 2
				} else if (active == 2) {
					this.payState = 1
				}
				this.getLeaveLog(this.payState)
			},
			getLeaveLog(payState){
				this.$api.getLeaveLog({
					status:payState
				}).then((res) => {
					if (res.data.code == 200) {
						console.log(res.data.dataMap)
						this.LeaveLog = res.data.dataMap
					}
				})
			}
		}
	}
</script>

<style scoped>
	.all-box{
		overflow: hidden;
	}
	.applyname {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.line_l {
		width: 690rpx;
		height: 2rpx;
		background-color: #EEEEEE;
		margin: 0 auto;
		margin-top: 20rpx;
	}

	.casetype {
		display: flex;
		margin-top: 12rpx;
	}

	.casetype>view:nth-child(1) {
		width: 158rpx;
		line-height: 36rpx;
	}

	.casetype>view:nth-child(2) {
		width: 606rpx;
		line-height: 36rpx;
	}

	.case {
		display: flex;
		margin-top: 16rpx;
	}

	.case>view:nth-child(1) {
		width: 158rpx;
		line-height: 36rpx;
		font-weight: 500;
	}

	.case>view:nth-child(2) {
		width: 606rpx;
		line-height: 36rpx;
	}

	.pannel {
		width: 690rpx;
		background-color: #FFFFFF;
		padding: 30rpx 30rpx 30rpx 30rpx;
		color: #333333;
		font-size: 24rpx;
		margin-top: 20rpx;
	}

	.page-section-spacing {
		background-color: #f3f3f3;
		display: flex;
		justify-content: space-around;
	}

	.line {
		height: 8rpx;
		background-color: #FF5551;
		width: 50%;
		margin: auto;
		border-radius: 50rpx;
		margin-top: 5rpx;
	}

	.line-gray {
		height: 1rpx;
		width: 660rpx;
		background-color: #f0f0f0;
		margin: auto;
		border-radius: 24rpx;
		z-index: 99;
	}

	.scroll-view_H {
		white-space: nowrap;
		width: 90%;

	}

	.scroll-view-item_H>view {
		font-size: 33rpx;
		/* border: 1px solid red; */
		line-height: 80rpx;

	}

	.scroll-view-item_H {
		display: inline-block;
		width: 150rpx;
		height: 75rpx;

		text-align: center;
		font-size: 34rpx;
		/* border: 1px solid red; */
		/* margin-left: 28rpx; */
	}

	,
	.tab-bar {
		/* #ifdef APP-PLUS */
		width: 750rpx;
		/* #endif */
		height: 42px;
		flex-direction: row;
		/* #ifndef APP-PLUS */
		white-space: nowrap;
		/* #endif */
	}

	,
	.tabs {
		flex: 1;
		flex-direction: column;
		background-color: #ffffff;
	}

	.active {
		color: #a7a7a7;
	}

	.casetype1 {
		display: flex;
		margin-top: 12rpx;
	}

	.casetype1>view:nth-child(1) {
		width: 158rpx;
		line-height: 36rpx;
		font-weight: 500;
		color: #666666;
	
	}

	.casetype1>view:nth-child(2) {
		width: 606rpx;
		line-height: 36rpx;
		font-weight: 500;
		color: #666666;
	}

	.case1 {
		display: flex;
		margin-top: 16rpx;
	}

	.case1>view:nth-child(1) {
		width: 158rpx;
		line-height: 36rpx;
		font-weight: 500;
		color: #666666;
	}

	.case1>view:nth-child(2) {
		width: 606rpx;
		line-height: 36rpx;
		font-weight: 500;
		color: #666666;
	}

	.pannel1 {
		width: 690rpx;
		background-color: #FFFFFF;
		padding: 30rpx 30rpx 30rpx 30rpx;
		margin-top: 20rpx;
	}

	.applyname1 {
		display: flex;
		align-items: center;
		justify-content: space-between;
		color: #666666;
	}

	.applyname1>view:nth-child(2) {
		font-size: 24rpx
	}
	.applyname>view:nth-child(2) {
		font-size: 24rpx
	}
</style>
